package com.dzsw.demo.chgdb.controller;

import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dzsw.demo.chgdb.entity.TbBaseSmsHistory;
import com.dzsw.demo.chgdb.mapper.StuMapper;
import com.dzsw.demo.chgdb.mapper.TbBaseSmsHistoryMapper;
import com.dzsw.demo.chgdb.utils.JsonUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/d")
public class DemoController {

    @Resource
    private StuMapper stuMapper;

    @Resource
    private TbBaseSmsHistoryMapper smsHistoryMapper;

    @GetMapping("/t")
    public String demo() {
        return "ok";
    }


    @DS("db2")
    @GetMapping("/db2")
    public String db2Stu() {
        return JsonUtil.toJson(stuMapper.getAllList());
    }

    @DS("db1")
    @GetMapping("/db1")
    public String db1Sms() {
        QueryWrapper<TbBaseSmsHistory> queryWrapper = new QueryWrapper<>();
        return JsonUtil.toJson(smsHistoryMapper.selectList(queryWrapper));
    }
}
